package com.zust513.service.impl;

import com.zust513.entity.Account;
import com.zust513.entity.Order;
import com.zust513.entity.Transaction;
import com.zust513.entity.User;
import com.zust513.mapper.ClientMapper;
import com.zust513.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
@Transactional
public class ClientServiceI implements ClientService {

    @Autowired
    ClientMapper clientMapper;


    @Override
    public Account selectAccountById(Integer id) {
        Account account = clientMapper.selectAccountById(id);
        return account;
    }

    @Override
    public void updateUserInfo(User user) {
        clientMapper.updateUserInfo(user);
    }

    @Override
    public User selectUserById(Integer id) {
        User user = clientMapper.selectUserById(id);
        return user;
    }

    @Override
    public void updatePassword(String newpassword, Integer id) {
        clientMapper.updatePassword(newpassword, id);
    }

    @Override
    public void insertOrder(Order order) {
        clientMapper.insertOrder(order);
    }

    @Override
    public Order selectLatestOrderByUserId(Integer id) {
        Order order = clientMapper.selectLatestOrderByUserId(id);
        return order;
    }

    @Override
    public void updateAccountPay(Integer userId, BigDecimal subtract, BigDecimal add) {
        clientMapper.updateAccountPay(userId, subtract, add);
    }

    @Override
    public void insertTransaction(Transaction transaction) {
        clientMapper.insertTransaction(transaction);
    }

    @Override
    public void updateAccountRecharge(Integer userId, BigDecimal totalRecharge, BigDecimal balance) {
        clientMapper.updateAccountRecharge(userId, totalRecharge, balance);
    }

    @Override
    public void insertTransactionRecharge(Transaction transaction) {
        clientMapper.insertTransactionRecharge(transaction);
    }

    @Override
    public BigDecimal sumExpenseAmountByAccountId(Integer accountId) {
        return clientMapper.sumExpenseAmountByAccountId(accountId);
    }

    @Override
    public Integer countExpenseRecordsByAccountId(Integer accountId) {
        return clientMapper.countExpenseRecordsByAccountId(accountId);
    }

    @Override
    public List<Transaction> getTransactionsByAccountId(Integer accountId) {
        return clientMapper.getTransactionsByAccountId(accountId);
    }

    @Override
    public List<Order> getOrdersByUserId(Integer userId) {
        return clientMapper.getOrdersByUserId(userId);
    }

    @Override
    public Order selectOrderByOrderId(Integer orderId) {
        return clientMapper.selectOrderByOrderId(orderId);
    }

    @Override
    public void updateDeliveryStatusToCompleted(Integer orderId) {
        clientMapper.updateDeliveryStatusToCompleted(orderId);
    }

}
